package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.service.SetMealService;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SetMealMapper {



    /**
     * 套裁和分类的联系
     * @param id
     * @return
     */
    @Select("select  count(*) from  setmeal where category_id=#{id}")
    int findByID(Long id);

    /**
     * 新增套餐
     *
     */
    @AutoFill(value = OperationType.INSERT)
    void add(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> page(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 根据id查询套餐
     * @param id
     * @return
     */
    @Select("select * from setmeal where id=#{id}")
    Setmeal findByid(Long id);

    /**
     * 修改套餐
     */
    void update(Setmeal setmeal);

    /**
     * 删除套餐
     */
    @Delete("delete from setmeal where id=#{id}")
    void delete(Long id);

    /**
     * APP 端查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishBysetmealID(Long setmealId);

    /**
     * 套餐总览
     * @param enable
     * @return
     */
    @Select("select  count(*) from setmeal where status=#{enable}")
    Integer findStatusSETMEAL(Integer enable);
}
